package com.liuzw.order.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


/**
 * @Author 刘志伟
 * @create 2023/2/8 11:18
 */
@Aspect
@Component
public class LogAspect {
    private static final Logger logger = LoggerFactory.getLogger(LogAspect.class);

    @Pointcut("@annotation(com.liuzw.order.annotation.Log)")
    public void logPointCut(){

    }

    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable{
        long beginTime = System.currentTimeMillis();

        // 执行方法
        Object result = point.proceed();
        // 执行时长（毫秒）
        long time = System.currentTimeMillis()-beginTime;
        logger.info("消耗的时间为{}毫秒",time);
        return result;
    }

    void saveLog(ProceedingJoinPoint point, long time) throws Throwable{

    }
}
